package view;


import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridLayout;
import java.awt.Insets;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

import Controller.Controller;
import Controller.ControllerMonoThread;


public class HomeMonoThread extends JFrame{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel jpaneLeft;
	private JPanel jpaneRight;
	private JPanel jpaneBottom;
	private static JTextField fieldNbAlgo;
	private static JTextField fieldPoolSize;
	private static JTextField fieldCallPutFlag;
	private static JTextField fieldS;
	private static JTextField fieldX;
	private static JTextField fieldT;
	private static JTextField fieldR;
	private static JTextField fieldB;
	private static JTextField fieldV;
	private static JTextField fieldNSteps;
	private static JTextField fieldNSimulations;
	private double tmpDouble;
	private int tmpInteger;

	
	
	public HomeMonoThread() {
		
		//JFRAME Parameters
	    setTitle("Monte Carlo : MONO THREAD");
	    setSize(new Dimension(700, 500));
	    setLocationRelativeTo(null);
	    setDefaultCloseOperation(EXIT_ON_CLOSE);
		setVisible(true);
		this.build();
	}
	
	private void build(){
          
		jpaneLeft = new JPanel();
		jpaneLeft.setLayout(new GridLayout(11,4));

		//- Ajout de ce composant au container en spécifiant une contrainte de type GridBagConstraints. */
		GridBagConstraints gbc = new GridBagConstraints();
		gbc.insets = new Insets(10, 60, 0, 160);
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.weighty = 1;
		gbc.weighty = 1;
		
				
		//Call Put Flag
		gbc.gridx  = 0;
		gbc.gridy  = 0;
		
		JLabel labelCallPutFlag = new JLabel("Call Put Flag : ");
		jpaneLeft.add(labelCallPutFlag, gbc);

		gbc.gridx  = 1;
		gbc.gridy  = 0;
		
		fieldCallPutFlag = new JTextField();
		fieldCallPutFlag.setPreferredSize(new Dimension(50,20));
		jpaneLeft.add(fieldCallPutFlag, gbc);
		
		//S
		gbc.gridx  = 0;
		gbc.gridy  = 1;
		
		JLabel labelS = new JLabel("S : ");
		jpaneLeft.add(labelS, gbc);

		gbc.gridx  = 1;
		gbc.gridy  = 1;

		
		fieldS = new JTextField();
		fieldS.setPreferredSize(new Dimension(50,20));
		jpaneLeft.add(fieldS, gbc);
		
		//X
		gbc.gridx  = 0;
		gbc.gridy  = 2;
		
		JLabel labelX = new JLabel("X : ");
		jpaneLeft.add(labelX, gbc);

		gbc.gridx  = 1;
		gbc.gridy  = 2;
		gbc.weightx = 1;
		
		fieldX = new JTextField();
		fieldX.setPreferredSize(new Dimension(50,20));
		jpaneLeft.add(fieldX, gbc);		
		
		//T
		gbc.gridx  = 0;
		gbc.gridy  = 2;
		
		JLabel labelT = new JLabel("T : ");
		jpaneLeft.add(labelT, gbc);

		gbc.gridx  = 1;
		gbc.gridy  = 2;
		gbc.weightx = 1;
		
		fieldT = new JTextField();
		fieldT.setPreferredSize(new Dimension(50,20));
		jpaneLeft.add(fieldT, gbc);	
		
		//R
		gbc.gridx  = 0;
		gbc.gridy  = 2;
		
		JLabel labelR = new JLabel("R : ");
		jpaneLeft.add(labelR, gbc);

		gbc.gridx  = 1;
		gbc.gridy  = 2;
		gbc.weightx = 1;
		
		fieldR = new JTextField();
		fieldR.setPreferredSize(new Dimension(50,20));
		jpaneLeft.add(fieldR, gbc);	
		
		//B
		gbc.gridx  = 0;
		gbc.gridy  = 2;
		
		JLabel labelB = new JLabel("B : ");
		jpaneLeft.add(labelB, gbc);

		gbc.gridx  = 1;
		gbc.gridy  = 2;
		gbc.weightx = 1;
		
		fieldB = new JTextField();
		fieldB.setPreferredSize(new Dimension(50,20));
		jpaneLeft.add(fieldB, gbc);	
		
		this.getContentPane().add(jpaneLeft, BorderLayout.WEST);
		
		//V
		gbc.gridx  = 0;
		gbc.gridy  = 2;
		
		JLabel labelV = new JLabel("V : ");
		jpaneLeft.add(labelV, gbc);

		gbc.gridx  = 1;
		gbc.gridy  = 2;
		gbc.weightx = 1;
		
		fieldV = new JTextField();
		fieldV.setPreferredSize(new Dimension(50,20));
		jpaneLeft.add(fieldV, gbc);	
		
		this.getContentPane().add(jpaneLeft, BorderLayout.WEST);
		
		//nStep
		gbc.gridx  = 0;
		gbc.gridy  = 2;
		
		JLabel labelNSteps = new JLabel("nStep : ");
		jpaneLeft.add(labelNSteps, gbc);

		gbc.gridx  = 1;
		gbc.gridy  = 2;
		gbc.weightx = 1;
		
		fieldNSteps = new JTextField();
		fieldNSteps.setPreferredSize(new Dimension(50,20));
		jpaneLeft.add(fieldNSteps, gbc);	
		
		//nSimulations
		gbc.gridx  = 0;
		gbc.gridy  = 2;
		
		JLabel labelNSimulations = new JLabel("nSimulations : ");
		jpaneLeft.add(labelNSimulations, gbc);

		gbc.gridx  = 1;
		gbc.gridy  = 2;
		gbc.weightx = 1;
		
		fieldNSimulations = new JTextField();
		fieldNSimulations.setPreferredSize(new Dimension(50,20));
		jpaneLeft.add(fieldNSimulations, gbc);	
				
		this.getContentPane().add(jpaneLeft, BorderLayout.WEST);
		
		//Ajout du panel de droite 
		jpaneRight = new JPanel();
		//- Ajout de ce composant au container en spécifiant une contrainte de type GridBagConstraints. */
		GridBagConstraints gbcRight = new GridBagConstraints();
		gbcRight.insets = new Insets(10, 60, 0, 160);
		gbcRight.fill = GridBagConstraints.HORIZONTAL;
		gbcRight.weighty = 0.2;
		gbcRight.weighty = 0.2;
		
		
		//Nombre de threads par Algorithme de Monte Carlo
		gbcRight.gridx  = 0;
		gbcRight.gridy  = 0;
		
		JLabel labelAff = new JLabel("Affichage : ");
		jpaneRight.add(labelAff, gbc);
		
		jpaneRight.setLayout(new GridLayout(11,2));
		this.getContentPane().add(jpaneRight, BorderLayout.EAST);
		
		//Ajout des boutons a la fenetre
		jpaneBottom = new JPanel();
		
		jpaneBottom.add(new JButton(new ControllerMonoThread(this)));
		this.getContentPane().add(jpaneBottom, BorderLayout.SOUTH);
		 
		this.writeLogField();
		this.pack();
		this.setVisible(true);
	}
	
	public void writeLogField() {  
        SwingUtilities.invokeLater(new Runnable() {  
			@Override  
            public void run() {  
                fieldCallPutFlag.setText("c");  
        		fieldS.setText("40");
        		fieldX.setText("50");
                fieldT.setText("0.5");
                fieldR.setText("0.06");
                fieldB.setText("0.1");
        		fieldV.setText("0.45");
        		fieldNSteps.setText("168");
        		fieldNSimulations.setText("100000");

            }  
        });  
    }  
	
	public String getFieldCallPutFlag(){
		return fieldCallPutFlag.getText();
	}
 
	public double getFieldS(){
		tmpDouble=Double.parseDouble(fieldS.getText());
		return tmpDouble;
	}
	
	public double getFieldX(){
		tmpDouble=Double.parseDouble(fieldX.getText());
		return tmpDouble;
	}
 
	public Double getFieldT(){
		tmpDouble=Double.parseDouble(fieldT.getText());
		return tmpDouble;
	}
	
	public Double getFieldR(){
		tmpDouble=Double.parseDouble(fieldR.getText());
		return tmpDouble;
	}
 
	public Double getFieldB(){
		tmpDouble=Double.parseDouble(fieldB.getText());
		return tmpDouble;
	}
	
	public Double getFieldV(){
		tmpDouble=Double.parseDouble(fieldV.getText());
		return tmpDouble;
	}
 
	public int getFieldNSteps(){
		tmpInteger=Integer.parseInt(fieldNSteps.getText());
		return tmpInteger;
	}
	
	public int getFieldNSimulations(){
		tmpInteger=Integer.parseInt(fieldNSimulations.getText());
		return tmpInteger;
	}	
}


